package cn.com.pc.content.domain.tag;

import cn.com.pc.content.domain.Biz;
import cn.com.pc.content.domain.Site;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

@Repository
public interface TagRepository extends JpaRepository<Tag, Long>, JpaSpecificationExecutor<Tag> {
    Tag findBySiteAndBizAndName(Site site, Biz biz, String name);

    @Transactional
    @Modifying
    @Query(value = "update Tag t set t.treeId=0 where t.treeId=:tree_id")
    int updateTreeId(@Param("tree_id") Long tree_id);

    boolean existsByTreeId(Long treeId);
}

